package com.yusi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yusi.entity.City;
import com.yusi.entity.FlightInfo;
import com.yusi.entity.FlightMana;
import com.yusi.entity.dto.FilghtInfos;
import com.yusi.entity.dto.GetCity;
import com.yusi.entity.dto.RespBean;
import com.yusi.service.ICityService;
import com.yusi.service.IFlightInfoService;
import com.yusi.service.IFlightManaService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yusi
 * @since 2022-01-11
 */
@RestController
@RequestMapping("/flight/select")
public class FlightInfoController {

//    @ApiOperation("给航线添加航班")
//    @PostMapping()

    @Autowired
    private IFlightInfoService iFlightInfoService;
    @Autowired
    private IFlightManaService iFlightManaService;


    @ApiOperation("获取所有的航线")
    @GetMapping("/list")
    public List<FilghtInfos> getFilghtInfos(){
        return iFlightInfoService.getFilghtInfos();

    }
    @ApiOperation("按格式获取所有的航班")
    @GetMapping("/air/{dis}")
    public List<GetCity> getairbydis(@PathVariable Double dis){
      return iFlightManaService.getairbydis(dis);
    }
    @ApiOperation("新增接口")
    @PostMapping("/")
    public RespBean setair(@RequestBody FlightInfo flightMana ){
        if (iFlightInfoService.save(flightMana)){
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }
    @ApiOperation("修改接口")
    @PutMapping("/")
    public RespBean updair(@RequestBody FlightInfo flightInfo){
        if (iFlightInfoService.updateById(flightInfo)){
            return RespBean.success("修改成功！");
        }
        return  RespBean.error("修改失败！");
    }
    @ApiOperation("删除接口！")
    @DeleteMapping("/{id}")
    public RespBean delAir(@PathVariable Integer id){
        if (iFlightInfoService.removeById(id)){
            return RespBean.success("删除成功！");
        }
        return  RespBean.error("删除失败！");
    }




}
